package com.tanhua.listener;

import com.tanhua.api.mongo.PublishApi;
import com.tanhua.mongo.Publish;
import com.tanhua.template.HuaWeiUGCTemplate;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@RocketMQMessageListener(topic = "tanhua-quanzi",consumerGroup = "tanhua-quanzi-group")
@Component
public class HuaWeiListener implements RocketMQListener<String> {

    @Reference
    private PublishApi publishApi;

    @Autowired
    private HuaWeiUGCTemplate huaWeiUGCTemplate;
    @Override
    public void onMessage(String publishId) {

        System.out.println("我开始做审核了..");

        // 根据publishId获取publish对象
        Publish publish = publishApi.findById(publishId);
        //文字审核
        boolean flag1 = huaWeiUGCTemplate.textContentCheck(publish.getTextContent());
        //图片审核
        List<String> list = publish.getMedias();
        boolean flag2 = huaWeiUGCTemplate.imageContentCheck(list.toArray(new String[]{}));

        //状态（审核不通过）
        int state=2;

        if(flag1 && flag2){
            state=1; //审核通过
        }

        //修改
        publishApi.updateState(publishId,state);


    }
}
